package fr.afcepf.ai89.esharing.data;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.ai89.esharing.entity.Emprunt;
import fr.afcepf.ai89.esharing.entity.MouvementsSolde;
import fr.afcepf.ai89.esharing.entity.Proprietaire;

@Stateless
public class DAOMouvementsSolde implements IDAOMouvementsSolde {

	@PersistenceContext(unitName = "ESharingPhase22")
	EntityManager em;

	@Override
	public MouvementsSolde getMouvSolde(int idMouvSolde) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MouvementsSolde> getMouvsSolde() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MouvementsSolde> getMouvsSolde(Proprietaire prop) {
		
		Query hql = em.createQuery("SELECT ms FROM MouvementsSolde ms " + 
				   "WHERE ms.proprietaire.idUtilisateur = :param");
		
		hql.setParameter("param", prop.getIdUtilisateur());
		List<MouvementsSolde> movs = (List<MouvementsSolde>)hql.getResultList();
		
		return movs;
	}

	@Override
	public int transagir(MouvementsSolde mouvSolde) {
		
		mouvSolde.setDateMouvement(new Date());
		em.persist(mouvSolde);
		
		Query hql = em.createQuery("SELECT MAX(idMouvementSolde) FROM MouvementsSolde ms");
		int idMS = (Integer)hql.getSingleResult();
		return idMS;
		
	}

	@Override
	public int majFiscRecord(MouvementsSolde mouvSolde) {
		// TODO Auto-generated method stub
		return 0;
	}

}
